package com.spzx.order;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.BaseEntity;

/**
 * 代码生成器
 */
public class GenMP {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://192.168.100.254:3306/spzx-order?characterEncoding=utf-8&useSSL=false", "root", "root")
                .globalConfig(builder -> builder
                        .author("atguigu")
                        .outputDir("D:/Down/Java/spzx/order")
                        // 配置代码生成的过程中日期类型为 java.util.Date，默认是 java.sql.Date
                        .dateType(DateType.ONLY_DATE)
                        // 配置代码生成完成后是否打开文件夹，默认是 true(不打开)
                        .disableOpenDir()
                )
                // 配置包名
                .packageConfig(builder -> builder
                        // 设置父包名
                        .parent("com.spzx.order")
                        .entity("domain")
                        .mapper("mapper")
                        .xml("mapper.order")
                        .service("service")
                        .serviceImpl("service.impl")
                        .controller("controller")
                )
                // 配置策略
                .strategyConfig(builder -> builder
                                .addInclude(
                                        "order_info",
                                        "order_item",
                                        "order_log") // 设置需要生成的表名
                                // 配置实体类
                                .entityBuilder()
                                // 允许生成 lombok注解
                                .enableLombok()
                                // 指定继承的父类
                                .superClass(BaseEntity.class)
                                .addSuperEntityColumns(
                                        "id",
                                        "create_by",
                                        "create_time",
                                        "update_by",
                                        "update_time",
                                        "remark",
                                        "del_flag")
                                //.addIgnoreColumns()
                                // 配置是否覆盖文件，默认是 false
                                .enableFileOverride()

                                // 配置 service
                                .serviceBuilder()
                                //.formatServiceFileName("I%sService")
                                .enableFileOverride()

                                // 配置 controller
                                .controllerBuilder()
                                .superClass(BaseController.class)
                                // 配置是否开启 @RestController注解，默认是 false
                                .enableRestStyle()
                                .enableFileOverride()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}